#include "stringutil.hpp"
char* replaceChars(char* src,char* list){
	char* original = src;
	while(list[0]&&list[1]){
		src = original;
		while(*src){
			if(src[0]==list[0]) src[0] = list[1];
			src++;
		} list+=2;}
	return original;
}
char* removeDuplicates(char* src,char* data){
	while(*data){
		char  dtr = *data;
		char* str = src;
		while(*str){
			char* finish = str;
			while(*finish==dtr) finish++;
			if(finish>str) memcpy(str+1,finish,strlen(finish)+1);
			str++;
		} data++; }
	char* ret = new char[strlen(src)+1];
	strncpy(ret,src,strlen(src)+1);
	delete[] src;
	return ret;
}
char* removeAll(char *src, char* data){
	char* optr = src,*bptr;
	unsigned int count;
	while(*data){
		optr = src;
		while(*optr){
			bptr = optr;
			count = 0;
			while(*optr==*data) count++,optr++;
			if(count) memcpy(bptr,bptr+count,strlen(bptr+count)+2);
			optr++;
		}
		data++;
	}
	char* ret = new char[strlen(src)+1];
	strncpy(ret,src,strlen(src)+1);
	delete[] src;
	return ret;
}
char* getString(ifstream& is){
	if(!is.is_open()) return NULL;
	unsigned int pos = is.tellg();
	is.seekg(0,ios_base::end);
	unsigned int size = is.tellg();
	is.seekg(0,ios_base::beg);
	char* ret = new char[size+1];
	ret[size] = '\0';
	is.read(ret,size);
	is.seekg(pos,ios_base::beg);
	return ret;
}
char** splitString(char* src,char dltr){
	char* optr = src;
	unsigned int count = 1;
	while(*optr){
		if(*optr == dltr) count++;
		optr++;
	}
	char** ret = new char*[count+1];
	ret[ count ] = NULL;
	ret[ count = 0] = optr = src;
	while(*optr){
		if( optr[0]==dltr){
			optr[0] = '\0';
			if(optr[1]) ret[++count] = ++optr;
		} else optr++;
	}
	return ret;
}